﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.Migrations;
using RBOSS.Data;
using RBOSS.Business.CustomerModule;

namespace RBOSS.Business.AdminModule
{
    public class Vendors
    {
        private readonly RBOSSEntities _rBossEntities=new RBOSSEntities();

        public void AddVendor(string userEmail, string password, string firstName, string lastName, string phoneNo, string city, string provience, string country, string postalCode, int roleid)
        {
            int userid = _rBossEntities.Users.Select(e => e.UserId).Max();
            var user = new User
            {
                Email = userEmail,
                Country = country,
                City = city,
                FirstName = firstName,
                LastName = lastName,
                Password = password,
                PhoneNo = phoneNo,
                PostalCode = postalCode,
                Province = provience,
                RoleId =roleid,
                UserId = userid + 1,
                
            };
            //var customerItem = new CustomerItem();

            //customerItem.Email = userEmail;
            //customerItem.FirstName = firstName;
            //customerItem.LastName = lastName;
            //customerItem.Password = password;
            //    customerItem.Password = customer.Password;
            //    customerItem.PhoneNumber = phoneNo;
            //    customerItem.PostalCode = postalCode;
            //    customerItem.City = customer.City;
            //    customerItem.Provience = provience;
            //    customerItem.Country = customer.Country;
            //    customerItem.rol = roleid;
            

            _rBossEntities.Users.Add(user);
            _rBossEntities.SaveChanges();
        }
        public bool CheckEmailAvailability(string emailAddress)
        {
            try
            {
                var val= _rBossEntities.Users.Where(e => e.Email == emailAddress).Select(e => e.UserId).FirstOrDefault();
                if (_rBossEntities.Users.Where(e => e.Email == emailAddress).Select(e => e.UserId).FirstOrDefault() == 0)
                    return true;

            }
            catch (Exception)
            {

                return true;
            }
            
        
  
            return false;
        }
        public void addBankDetails(string userEmail,string accountNumber,string accountType,string bankName,string bankBranch)
        {
            int userid = _rBossEntities.Users.Where(e => e.Email == userEmail).Select(e => e.UserId).FirstOrDefault();
            var bankdetail = new BankDetail
            {
                UserId=userid,
                AccountNumber=accountNumber,
                AccountType=accountType,
                BankName=bankName,
                BankBranch=bankBranch,

            };
            _rBossEntities.BankDetails.Add(bankdetail);
            _rBossEntities.SaveChanges();
        }
    }
}
